﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Alos.IService;
using PetaPoco;
using Alos.Entity;

namespace Alos.Service
{
    public abstract class BaseService<TEntity> : IBaseService<TEntity> where TEntity : class
    {
        public BaseService()
        {
            Context = Model.GetInstance();
        }
        public Database Context { get; set; }
        public IEnumerable<TEntity> Query(string sql, params object[] args)
        {
            return Context.Query<TEntity>(sql, args);
        }
        public IEnumerable<TEntity> Query(Sql sql)
        {
            return Context.Query<TEntity>(sql);
        }
        public IEnumerable<TRet> Query<T1, T2, TRet>(Func<T1, T2, TRet> cb, string sql, params object[] args)
        {
            return Context.Query<T1, T2, TRet>(cb, sql, args);
        }
        public IEnumerable<TRet> Query<T1, T2, T3, TRet>(Func<T1, T2, T3, TRet> cb, string sql, params object[] args)
        {
            return Context.Query<T1, T2, T3, TRet>(cb, sql, args);
        }
        public IEnumerable<TRet> Query<T1, T2, T3, T4, TRet>(Func<T1, T2, T3, T4, TRet> cb, string sql, params object[] args)
        {
            return Context.Query<T1, T2, T3, T4, TRet>(cb, sql, args);
        }
        public IEnumerable<TRet> Query<T1, T2, TRet>(Func<T1, T2, TRet> cb, Sql sql)
        {
            return Context.Query<T1, T2, TRet>(cb, sql);
        }
        public IEnumerable<TRet> Query<T1, T2, T3, TRet>(Func<T1, T2, T3, TRet> cb, Sql sql)
        {
            return Context.Query<T1, T2, T3, TRet>(cb, sql);
        }
        public IEnumerable<TRet> Query<T1, T2, T3, T4, TRet>(Func<T1, T2, T3, T4, TRet> cb, Sql sql)
        {
            return Context.Query<T1, T2, T3, T4, TRet>(cb, sql);
        }
        public IEnumerable<T1> Query<T1, T2>(string sql, params object[] args)
        {
            return Context.Query<T1, T2>(sql, args);
        }
        public IEnumerable<T1> Query<T1, T2, T3>(string sql, params object[] args)
        {
            return Context.Query<T1, T2, T3>(sql, args);
        }
        public IEnumerable<T1> Query<T1, T2, T3, T4>(string sql, params object[] args)
        {
            return Context.Query<T1, T2, T3, T4>(sql, args);
        }
        public IEnumerable<T1> Query<T1, T2>(Sql sql)
        {
            return Context.Query<T1, T2>(sql);
        }
        public IEnumerable<T1> Query<T1, T2, T3>(Sql sql)
        {
            return Context.Query<T1, T2, T3>(sql);
        }
        public IEnumerable<T1> Query<T1, T2, T3, T4>(Sql sql)
        {
            return Context.Query<T1, T2, T3, T4>(sql);
        }
        public IEnumerable<TRet> Query<TRet>(Type[] types, object cb, string sql, params object[] args)
        {
            return Context.Query<TRet>(types, cb, sql, args);
        }
        public List<TEntity> Fetch(string sql, params object[] args)
        {
            return Context.Fetch<TEntity>(sql, args);
        }
        public List<TEntity> Fetch(Sql sql)
        {
            return Context.Fetch<TEntity>(sql);
        }
        public Page<TEntity> Page(long page, long itemsPerPage, string sqlCount, object[] countArgs, string sqlPage, object[] pageArgs)
        {
            return Context.Page<TEntity>(page, itemsPerPage, sqlCount, countArgs, sqlPage, pageArgs);
        }
        public Page<TEntity> Page(long page, long itemsPerPage, string sql, params object[] args)
        {
            return Context.Page<TEntity>(page, itemsPerPage, sql, args);
        }
        public Page<TEntity> Page(long page, long itemsPerPage, Sql sql)
        {
            return Context.Page<TEntity>(page, itemsPerPage, sql);
        }
        public Page<TEntity> Page(long page, long itemsPerPage, Sql sqlCount, Sql sqlPage)
        {
            return Context.Page<TEntity>(page, itemsPerPage, sqlCount, sqlPage);
        }
        public List<TEntity> Fetch(long page, long itemsPerPage, string sql, params object[] args)
        {
            return Context.Fetch<TEntity>(page, itemsPerPage, sql, args);
        }
        public List<TEntity> Fetch(long page, long itemsPerPage, Sql sql)
        {
            return Context.Fetch<TEntity>(page, itemsPerPage, sql);
        }
        public List<TEntity> SkipTake(long skip, long take, string sql, params object[] args)
        {
            return Context.SkipTake<TEntity>(skip, take, sql, args);
        }
        public List<TEntity> SkipTake(long skip, long take, Sql sql)
        {
            return Context.SkipTake<TEntity>(skip, take, sql);
        }
        public bool Exists(object primaryKey)
        {
            return Context.Exists<TEntity>(primaryKey);
        }
        public bool Exists(string sqlCondition, params object[] args)
        {
            return Context.Exists<TEntity>(sqlCondition, args);
        }
        public TEntity Single(object primaryKey)
        {
            return Context.Single<TEntity>(primaryKey);
        }
        public TEntity Single(string sql, params object[] args)
        {
            return Context.Single<TEntity>(sql, args);
        }
        public TEntity Single(Sql sql)
        {
            return Context.Single<TEntity>(sql);
        }
        public TEntity SingleOrDefault(Sql sql)
        {
            return Context.SingleOrDefault<TEntity>(sql);
        }
        public TEntity SingleOrDefault(object primaryKey)
        {
            return Context.SingleOrDefault<TEntity>(primaryKey);
        }
        public TEntity SingleOrDefault(string sql, params object[] args)
        {
            return Context.SingleOrDefault<TEntity>(sql, args);
        }
        public TEntity First(string sql, params object[] args)
        {
            return Context.First<TEntity>(sql, args);
        }
        public TEntity First(Sql sql)
        {
            return Context.First<TEntity>(sql);
        }
        public TEntity FirstOrDefault(string sql, params object[] args)
        {
            return Context.FirstOrDefault<TEntity>(sql, args);
        }
        public TEntity FirstOrDefault(Sql sql)
        {
            return Context.FirstOrDefault<TEntity>(sql);
        }
        public List<TRet> Fetch<T1, T2, TRet>(Func<T1, T2, TRet> cb, string sql, params object[] args)
        {
            return Context.Fetch<T1, T2, TRet>(cb, sql, args);
        }
        public List<TRet> Fetch<T1, T2, T3, TRet>(Func<T1, T2, T3, TRet> cb, string sql, params object[] args)
        {
            return Context.Fetch<T1, T2, T3, TRet>(cb, sql, args);
        }
        public List<TRet> Fetch<T1, T2, T3, T4, TRet>(Func<T1, T2, T3, T4, TRet> cb, string sql, params object[] args)
        {
            return Context.Fetch<T1, T2, T3, T4, TRet>(cb, sql, args);
        }
        public List<TRet> Fetch<T1, T2, TRet>(Func<T1, T2, TRet> cb, Sql sql)
        {
            return Context.Fetch<T1, T2, TRet>(cb, sql);
        }
        public List<TRet> Fetch<T1, T2, T3, TRet>(Func<T1, T2, T3, TRet> cb, Sql sql)
        {
            return Context.Fetch<T1, T2, T3, TRet>(cb, sql);
        }
        public List<TRet> Fetch<T1, T2, T3, T4, TRet>(Func<T1, T2, T3, T4, TRet> cb, Sql sql)
        {
            return Context.Fetch<T1, T2, T3, T4, TRet>(cb, sql);
        }
        public List<T1> Fetch<T1, T2>(string sql, params object[] args)
        {
            return Context.Fetch<T1, T2>(sql, args);
        }
        public List<T1> Fetch<T1, T2, T3>(string sql, params object[] args)
        {
            return Context.Fetch<T1, T2, T3>(sql, args);
        }
        public List<T1> Fetch<T1, T2, T3, T4>(string sql, params object[] args)
        {
            return Context.Fetch<T1, T2, T3, T4>(sql, args);
        }
        public List<T1> Fetch<T1, T2>(Sql sql)
        {
            return Context.Fetch<T1, T2>(sql);
        }
        public List<T1> Fetch<T1, T2, T3>(Sql sql)
        {
            return Context.Fetch<T1, T2, T3>(sql);
        }
        public List<T1> Fetch<T1, T2, T3, T4>(Sql sql)
        {
            return Context.Fetch<T1, T2, T3, T4>(sql);
        }
        public IGridReader QueryMultiple(Sql sql)
        {
            return Context.QueryMultiple(sql);
        }
        public IGridReader QueryMultiple(string sql, params object[] args)
        {
            return Context.QueryMultiple(sql, args);
        }
        public object Insert(string tableName, object poco)
        {
            return Context.Insert(tableName, poco);
        }
        public object Insert(string tableName, string primaryKeyName, object poco)
        {
            return Context.Insert(tableName, primaryKeyName, poco);
        }
        public object Insert(string tableName, string primaryKeyName, bool autoIncrement, object poco)
        {
            return Context.Insert(tableName, primaryKeyName, autoIncrement, poco);
        }
        public object Insert(object poco)
        {
            return Context.Insert(poco);
        }
        public int Update(string tableName, string primaryKeyName, object poco, object primaryKeyValue)
        {
            return Context.Update(tableName, primaryKeyName, poco, primaryKeyValue);
        }
        public int Update(string tableName, string primaryKeyName, object poco, object primaryKeyValue, IEnumerable<string> columns)
        {
            return Context.Update(tableName, primaryKeyName, poco, primaryKeyValue, columns);
        }
        public int Update(string tableName, string primaryKeyName, object poco)
        {
            return Context.Update(tableName, primaryKeyName, poco);
        }
        public int Update(string tableName, string primaryKeyName, object poco, IEnumerable<string> columns)
        {
            return Context.Update(tableName, primaryKeyName, poco, columns);
        }
        public int Update(object poco, IEnumerable<string> columns)
        {
            return Context.Update(poco, columns);
        }
        public int Update(object poco)
        {
            return Context.Update(poco);
        }
        public int Update(object poco, object primaryKeyValue)
        {
            return Context.Update(poco, primaryKeyValue);
        }
        public int Update(object poco, object primaryKeyValue, IEnumerable<string> columns)
        {
            return Context.Update(poco, primaryKeyValue, columns);
        }
        public int Update(string sql, params object[] args)
        {
            return Context.Update(sql, args);
        }
        public int Update(Sql sql)
        {
            return Context.Update(sql);
        }
        public int Delete(string tableName, string primaryKeyName, object poco)
        {
            return Context.Update(tableName, primaryKeyName, poco);
        }
        public int Delete(string tableName, string primaryKeyName, object poco, object primaryKeyValue)
        {
            return Context.Update(tableName, primaryKeyName, poco, primaryKeyValue);
        }
        public int Delete(object poco)
        {
            return Context.Update(poco);
        }
        public int Delete(string sql, params object[] args)
        {
            return Context.Update(sql, args);
        }
        public int Delete(Sql sql)
        {
            return Context.Delete(sql);
        }
        public bool IsNew(string primaryKeyName, object poco)
        {
            return Context.IsNew(primaryKeyName, poco);
        }
        public bool IsNew(object poco)
        {
            return Context.IsNew(poco);
        }
        public void Save(string tableName, string primaryKeyName, object poco)
        {
            Context.Save(tableName, primaryKeyName, poco);
        }
        public void Save(object poco)
        {
            Context.Save(poco);
        }
        public int Execute(Sql sql)
        {
            return Context.Execute(sql);
        }
        public int Execute(string sql, params object[] args)
        {
            return Context.Execute(sql, args);
        }
        public TEntity ExecuteScalar(string sql, params object[] args)
        {
            return Context.ExecuteScalar<TEntity>(sql, args);
        }
        public TEntity ExecuteScalar(Sql sql)
        {
            return Context.ExecuteScalar<TEntity>(sql);
        }
    }
}
